package lol.clann.minecraft.springboot.api.bukkit.command.tabcomplete;

import lol.clann.minecraft.springboot.api.bukkit.command.TabComplete;
import org.bukkit.command.CommandSender;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author pyz
 * @date 2019/5/19 4:53 PM
 */
public abstract class AbstractListTabComplete implements TabComplete {

    protected abstract List<String> getCandidates(CommandSender sender, String alias, String[] args);

    @Override
    public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
        String keywords = args[args.length - 1].toLowerCase();
        List<String> candidates = new ArrayList<>();
        for (String tabCompleteCandidate : getCandidates(sender, alias, args)) {
            if (tabCompleteCandidate.toLowerCase().startsWith(keywords)) {
                candidates.add(tabCompleteCandidate);
            }
        }
        return candidates;
    }
}